const { Article } = require("../../models/article");
const pagination = require("mongoose-sex-page");

module.exports = async (req, res) => {
  const page = req.query.page || 1;
  //   let articles = await Article.find().populate("author");
  let result = await pagination(Article)
    .find()
    .page(page)
    .size(10)
    .display(5)
    .populate("author")
    .exec();
  result = JSON.parse(JSON.stringify(result));

  res.render("home/default", {
    articles: result,
    username: req.session.username,
  });
};
